// 获取当前账户下的商品
$(document).ready(function () {
    // 接收页面传递得参数id
    let id = location.search.split("=")[1];

    $.ajax({
        url: "http://jx.xuzhixiang.top/ap/api/detail.php",
        type: "get",
        data: {
            id: id
        },
        success: function (res) {

            console.log(res);

            // let detail=document.querySelector(".deta");
            // let str=`
            //         <img src="${res.data.pimg}">
            //         <p>${res.data.pname}</p>
            //         <p>￥${res.data.pprice}</p>
            //         <span id="minus">-</span>
            //         <input type="text" value=1 class="num">
            //         <span id="plus>+</span>
            //         <input type="button" data-id="${res.data.pid}" value="加入购物车" class="addBtn"/>
            // `;


            let obj = res.data;
            $('.qq').html(obj.pname),
                $('.zhaopian').attr("src", obj.pimg)

            //---------------------
            let oMinus = document.querySelector(".btn-reduce");
            let oPlus = document.querySelector(".btn-add");
            let oNum = document.querySelector(".text");
            let pid = $(".addBtn").attr(obj);
            console.log(pid);
            oMinus.onclick = function () {
                oNum.value--;
                if (oNum.value < 1) {
                    oNum.value = 1;
                }
            }
            oPlus.onclick = function () {
                oNum.value++;
            };
            oNum.onchange = function () {
                if (oNum.value < 1) {
                    oNum.value = 1;
                }
            };
            
            console.log(oNum.value)
            

            $(".addBtn").click(function () {
                let id = location.search.split("=")[1];
                $.ajax({

                    url: "http://jx.xuzhixiang.top/ap/api/add-product.php",
                    type: "get",
                    data: {
                        uid: 74806,
                        pid: id,
                        pnum: oNum.value
                    },
                    success: function (obj) {
                        console.log(obj);
                        console.log(oNum.value);
                        location.href = "../html/cart.html";
                    }
                })
            })
            //-----------------


        },


    })

})